package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"user-sys/conf"
)

var DB *gorm.DB
var err error

func MysqlLink() {
	Dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", conf.AppConf.Mysql.User, conf.AppConf.Mysql.Password, conf.AppConf.Mysql.Host, conf.AppConf.Mysql.Port, conf.AppConf.Mysql.Database)
	DB, err = gorm.Open(mysql.Open(Dsn))
	if err != nil {
		panic(err)
	}
	if err = DB.AutoMigrate(&User{}); err != nil {
		panic(err)
	}
	fmt.Println("数据库预处理完成")
}
